﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinFu.IoC.Interfaces;
using LinFu.IoC.Configuration;
using LinFu.IoC;

namespace CoreEx.Database.Client.Implementation
{
    [PostProcessor]
    public class ConnectionInfoPostProcessor : IPostProcessor
    {
        public void PostProcess(IServiceRequestResult result)
        {

            //Check to see if this a request for an IDbConnection
            if (result.ServiceType != typeof(IConnectionInfo))
                return;

            //A request for the default connection has been issued.
            if (string.IsNullOrEmpty(result.ServiceName))
                result.ActualResult = result.Container.GetService<IDefaultConnection>()
                    .Selector(result.Container.GetServices<IConnectionInfo>());                                    
        }
    }
}
